<?php
require '../../config.php';
	
	$_cual = $_REQUEST['id'];
	if($_cual == "rol")
	{	
		$registros=mysql_query("select idroles,nombre from  roles",$conexion) or
			die("Problemas en el select:".mysql_error());
		if (mysql_num_rows($registros) == 0)
		{
			echo "0";
		}
		else
		{	
			$data = array();
			while ($row = mysql_fetch_array($registros)) {
			    $data[] = $row['idroles'];
    			$data[] = _convert($row['nombre']);
			}
			
			echo json_encode($data);
		}
		mysql_close($conexion);
	}
	
	function _convert($content) {
		if(!mb_check_encoding($content, 'UTF-8')
		OR !($content === mb_convert_encoding(mb_convert_encoding($content, 'UTF-32', 'UTF-8' ), 'UTF-8', 'UTF-32'))) {
	
			$content = mb_convert_encoding($content, 'UTF-8');
	
			if (mb_check_encoding($content, 'UTF-8')) {
				// log('Converted to UTF-8');
			} else {
				// log('Could not converted to UTF-8');
			}
		}
		return $content;
	}
?>
